/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/* 
 * Copyright (c) 2009 City University of Hong Kong
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License m_version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * Author: Wilson Thong (wilsonwk@ee.cityu.edu.hk) 
 */
#include "packet-reorder-calculator-tag.h"
#include "ns3/uinteger.h"

namespace ns3 {
namespace eecityu {

NS_OBJECT_ENSURE_REGISTERED (PacketReorderCalculatorTag);

TypeId 
PacketReorderCalculatorTag::GetTypeId (void)
{
  static TypeId tid = TypeId ("ns3::eecityu::PacketReorderCalculatorTag")
    .SetParent<Tag> ()
    .AddConstructor<PacketReorderCalculatorTag> ()
    .AddAttribute ("Sequence",
                   "The sequence number for packets, starting from zero.",
                   UintegerValue(0),
                   MakeUintegerAccessor (&PacketReorderCalculatorTag::SetSeqNum,
                                         &PacketReorderCalculatorTag::GetSeqNum),
                   MakeUintegerChecker<uint64_t> ())
    ;
  return tid;
}

TypeId
PacketReorderCalculatorTag::GetInstanceTypeId (void) const
{
  return GetTypeId ();
}

PacketReorderCalculatorTag::PacketReorderCalculatorTag(void)
  : m_seqNum (0)
{
}

void 
PacketReorderCalculatorTag::SetSeqNum (uint64_t s)
{
  m_seqNum = s;
}

uint64_t 
PacketReorderCalculatorTag::GetSeqNum () const
{
  return m_seqNum;
}

uint32_t 
PacketReorderCalculatorTag::GetSerializedSize (void) const
{
  // m_value is 64 bits, or 8 bytes
  return 8;
}

void 
PacketReorderCalculatorTag::Serialize (TagBuffer i) const
{
  i.WriteU64 (m_seqNum);
}

void 
PacketReorderCalculatorTag::Deserialize (TagBuffer i)
{
  m_seqNum = i.ReadU64 ();
}

/**
 * \todo pring the tag value in binary format
 */
void 
PacketReorderCalculatorTag::Print (std::ostream &os) const
{
  os << m_seqNum;
}


} // namespace eecityu
} // namespace ns3
